#pragma once

#include "inc.h"
#include <assert.h>

namespace GLC {

typedef size_t handle_t;

/**
 * @brief The Texture2D class - managed reference to real texture object,
 * ctor increases references count to real texture, dtor decreases.
 * Manager will destroy real texture object when reference count become 0.
 */
class Texture2D
{
public:
    Texture2D(const std::string &name);
    ~Texture2D();

    void bind() const;
    static void unbind();

private:
    friend class Texture2DRef;

    std::string _name;
    handle_t _texture;
};

/**
 * @brief The Texture2DRef class - fast, but not managed reference to texture
 */
class Texture2DRef
{
public:
    static Texture2DRef createNull();

    Texture2DRef(const Texture2D &source);

    void bind() const;
    static void unbind();
    bool isNull() const;

private:
    Texture2DRef();

    handle_t _texture;
};

//template <GLenum t_target>
//class BaseTexture
//{
//public:
//    static void unbindTexture()
//    {
//        glBindTexture(t_target, texture);
//    }

//    inline void create()
//    {
//        assert(! _texture);
//        glGenTextures(1, &_texture);
//    }

//    inline void destroy()
//    {
//        assert(_texture);
//        glDeleteTextures(1, &_texture);
//        _texture = 0;
//    }

//    inline void bind()
//    {
//        assert(_texture);
//        glBindTexture(t_target, _texture);
//    }

//private:
//    GLuint _texture;
//};

//typedef BaseTexture<true, t_target>
//{
//}

} // namespace GLC
